{"ast":null,"code":"import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name closestTo\n * @category Common Helpers\n * @summary Return a date from the array closest to the given date.\n *\n * @description\n * Return a date from the array closest to the given date.\n *\n * @param {Date | Number} dateToCompare - the date to compare with\n * @param {Array<Date> | Array<number>} datesArray - the array to search\n * @returns {Date | undefined} the date from the array closest to the given date or undefined if no valid value is given\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030?\n * const dateToCompare = new Date(2015, 8, 6)\n * const result = closestTo(dateToCompare, [\n *   new Date(2000, 0, 1),\n *   new Date(2030, 0, 1)\n * ])\n * //=> Tue Jan 01 2030 00:00:00\n */\n\nexport default function closestTo(dirtyDateToCompare, dirtyDatesArray) {\n  requiredArgs(2, arguments);\n  var dateToCompare = toDate(dirtyDateToCompare);\n  if (isNaN(Number(dateToCompare))) return new Date(NaN);\n  var timeToCompare = dateToCompare.getTime();\n  var datesArray; // `dirtyDatesArray` is undefined or null\n\n  if (dirtyDatesArray == null) {\n    datesArray = []; // `dirtyDatesArray` is Array, Set or Map, or object with custom `forEach` method\n  } else if (typeof dirtyDatesArray.forEach === 'function') {\n    datesArray = dirtyDatesArray; // If `dirtyDatesArray` is Array-like Object, convert to Array. Otherwise, make it empty Array\n  } else {\n    datesArray = Array.prototype.slice.call(dirtyDatesArray);\n  }\n  var result;\n  var minDistance;\n  datesArray.forEach(function (dirtyDate) {\n    var currentDate = toDate(dirtyDate);\n    if (isNaN(Number(currentDate))) {\n      result = new Date(NaN);\n      minDistance = NaN;\n      return;\n    }\n    var distance = Math.abs(timeToCompare - currentDate.getTime());\n    if (result == null || distance < Number(minDistance)) {\n      result = currentDate;\n      minDistance = distance;\n    }\n  });\n  return result;\n}","map":{"version":3,"names":["toDate","requiredArgs","closestTo","dirtyDateToCompare","dirtyDatesArray","arguments","dateToCompare","isNaN","Number","Date","NaN","timeToCompare","getTime","datesArray","forEach","Array","prototype","slice","call","result","minDistance","dirtyDate","currentDate","distance","Math","abs"],"sources":["/data/messenger.client/node_modules/date-fns/esm/closestTo/index.js"],"sourcesContent":["import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name closestTo\n * @category Common Helpers\n * @summary Return a date from the array closest to the given date.\n *\n * @description\n * Return a date from the array closest to the given date.\n *\n * @param {Date | Number} dateToCompare - the date to compare with\n * @param {Array<Date> | Array<number>} datesArray - the array to search\n * @returns {Date | undefined} the date from the array closest to the given date or undefined if no valid value is given\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030?\n * const dateToCompare = new Date(2015, 8, 6)\n * const result = closestTo(dateToCompare, [\n *   new Date(2000, 0, 1),\n *   new Date(2030, 0, 1)\n * ])\n * //=> Tue Jan 01 2030 00:00:00\n */\n\nexport default function closestTo(dirtyDateToCompare, dirtyDatesArray) {\n  requiredArgs(2, arguments);\n  var dateToCompare = toDate(dirtyDateToCompare);\n  if (isNaN(Number(dateToCompare))) return new Date(NaN);\n  var timeToCompare = dateToCompare.getTime();\n  var datesArray; // `dirtyDatesArray` is undefined or null\n\n  if (dirtyDatesArray == null) {\n    datesArray = []; // `dirtyDatesArray` is Array, Set or Map, or object with custom `forEach` method\n  } else if (typeof dirtyDatesArray.forEach === 'function') {\n    datesArray = dirtyDatesArray; // If `dirtyDatesArray` is Array-like Object, convert to Array. Otherwise, make it empty Array\n  } else {\n    datesArray = Array.prototype.slice.call(dirtyDatesArray);\n  }\n\n  var result;\n  var minDistance;\n  datesArray.forEach(function (dirtyDate) {\n    var currentDate = toDate(dirtyDate);\n\n    if (isNaN(Number(currentDate))) {\n      result = new Date(NaN);\n      minDistance = NaN;\n      return;\n    }\n\n    var distance = Math.abs(timeToCompare - currentDate.getTime());\n\n    if (result == null || distance < Number(minDistance)) {\n      result = currentDate;\n      minDistance = distance;\n    }\n  });\n  return result;\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